Hệ thống quản lý ngân hàng máu trong php

1 <?php
2 /*
3  * To change
this license header, choose License Headers in Project Properties.
4  * To change
this template file, choose Tools | Templates
5  * and open the template
in the editor.
6  */
7
8 /**
9  * Description of DBConnect
10  *
11  * @author Vaibhav
12  */

13 class
DBConnect {
14     
private $db = NULL;
15
16     
const DB_SERVER = "localhost";
17     
const DB_USER = "root";
18     
const DB_PASSWORD = "";
19     
const DB_NAME = "donor";
20
21     
public function __construct() {
22         $dsn =
'mysql:dbname=' . self::DB_NAME . ';host=' . self::DB_SERVER;
23         
try {
24             $
this->db = new PDO($dsn, self::DB_USER, self::DB_PASSWORD);
25         }
catch (PDOException $e) {
26             
throw new Exception('Connection failed: ' .
27             $e->getMessage());
28         }
29         
return $this->db;
30     }
31     
32     
public function auth(){
33         session_start();
34         
if(! isset($_SESSION['username'])){
35             header(
"Location: http://localhost/BDManagement");
36         }
37     }
38     
public function authLogin(){
39         session_start();
40         
if(isset($_SESSION['username'])){
41             header(
"Location: http://localhost/BDManagement/home.php");
42         }
43     }
44     
45     
public function checkAuth(){
46         session_start();
47         
if(! isset($_SESSION['username'])){
48             
return false;
49         }
else {
50             
return true;
51         }
52     }
53
54
55     
public function login($username, $password){
56         $stmt = $
this->db->prepare("SELECT * FROM employees WHERE username=? AND password=?");
57         $stmt->execute([$username,$password]);
58         
if($stmt->rowCount() > 0){
59             session_start();
60             $emp = $stmt->fetchAll();
61             
foreach($emp as $e){
62                 $_SESSION[
'id'] = $e['id'];
63                 $_SESSION[
'username'] = $username;
64                 $_SESSION[
'password'] = $password;
65                 $_SESSION[
'firstName'] = $e['f_name'];
66                 $_SESSION[
'middleName'] = $e['m_name'];
67                 $_SESSION[
'lastName'] = $e['l_name'];
68                 $_SESSION[
'birthDay'] = $e['b_day'];
69                 $_SESSION[
'pcrNumber'] = $e['prc_nr'];
70                 $_SESSION[
'designation'] = $e['designation'];
71                 $_SESSION[
'landline'] = $e['landline'];
72                 $_SESSION[
'mobile'] = $e['mobile'];
73                 
74             }
75             
76             
return true;
77         }
else {
78             
return false;
79         }
80     }
81     
82     
public function addDonor($fname,$mname,$lname,$sex,$bType,$dob,$hAddress,$city,$donationDate,$stats,$temp,
83             $pulse,$bp,$weight,$hemoglobin,$hbsag,$aids,$malariaSmear,$hematocrit,$mobile,$phone){
84         $stmt = $
this->db->prepare("INSERT INTO donors (fname,mname,lname,sex,b_type,bday,h_address,city,don_date,stats,temp,pulse,bp,weight,"
85                 .
"hemoglobin,hbsag,aids,malaria_smear,hematocrit,mobile,phone)"
86                 .
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
87         $stmt->execute([$fname,$mname,$lname,$sex,$bType,$dob,$hAddress,$city,$donationDate,$stats,$temp,$pulse,$bp,$weight,
88             $hemoglobin,$hbsag,$aids,$malariaSmear,$hematocrit,$mobile,$phone]);
89         
return true;
90         
91     }
92     
93     
public function searchDonorWithBloodGroup($bloodGroup){
94         $stmt = $
this->db->prepare("SELECT * FROM donors WHERE b_type LIKE ?");
95         $stmt->execute([$bloodGroup]);
96         
return $stmt->fetchAll();
97     }
98     
99     
public function searchDonorByCity($city){
100         $stmt = $
this->db->prepare("SELECT * FROM donors WHERE city LIKE ?");
101         $stmt->execute([
"%".$city."%"]);
102         
return $stmt->fetchAll();
103     }
104     
105     
public function logout(){
106         session_start();
107         session_destroy();
108         header(
"Location: http://localhost/BDManagement/");
109     }
110     
111     
public function getDonorProfileById($id){
112         $stmt = $
this->db->prepare("SELECT * FROM donors WHERE id=?");
113         $stmt->execute([$id]);
114         
return $stmt->fetchAll();
115     }
116     
117 }


Gõ tìm kiếm nhanh...